内容数据库文件以及C#源码,通俗易懂,适合做数据库课设的同学
非常实用,C#跟JAVA的语法相似,会JAVA的同学看起来没压力哦
使用系统;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
使用System.Windows.Forms;
使用System.Data.SqlClient;
名称空间StudentSystem
{
公共局部类MainForm:表单
{
public MainForm()
{
InitializeComponent();
label1.Text = label1.Text Login.managename;
}
私人void button1_Click(object sender,EventArgs e)
{
Application.Exit();
}
private void button2_Click(object sender,EventArgs e)
{
Login.lo.Visible = true;
this.Close();
}
private void button3_Click(object sender,EventArgs e)
{
panel1.Visible = true;
panel2.Visible = false;
panel3.Visible = false;
panel4.Visible = false;
panel5.Visible = false;
}
private void button6_Click(object sender,EventArgs e)
{
panel2.Visible = true;
panel1.Visible = false;
panel3.Visible = false;
panel4.Visible = false;
panel5.Visible = false;
}
private void button7_Click(object sender,EventArgs e)
{
textBox1.Text =“”;
textBox2.Text =“”;
textBox4.Text =“”;
textBox5.Text =“”;
textBox6.Text =“”;
textBox7.Text =“”;
comboBox1.Text =“”;
}
private void button4_Click(object sender,EventArgs e)
{
字符串_number = textBox1.Text.Trim();
字符串_name = textBox2.Text.Trim();
字符串_sex = comboBox1.Text.Trim();
字符串_age = textBox4.Text.Trim();
字符串_colloge = textBox5.Text.Trim();
字符串_class = textBox6.Text.Trim();
字符串_phonenumber = textBox7.Text.Trim();
SqlConnection conn =新的SqlConnection(“数据源= .;初始目录= StudentSystem;用户ID = sa;密码= 123456”);
字符串strsql =“插入学生值('” _number“','” _name“','” _sex“','” _age“','” _colloge“','” _class“',
conn.Open();
int i = com2.ExecuteNonQuery();
如果(i> 0)System.Windows.Forms.MessageBox.Show(“添加成功!”,“成功!”);
conn.Close();
}
私有无效按钮5_Click(对象发送者,EventArgs e)
{
}
私有无效按钮8_Click(对象发送者,EventArgs e)
{
字符串_number = textBox8.Text.Trim();
字符串_item = comboBox2.Text.Trim();
字符串changeitem =“”;
if(_item ==“学号”)changeitem =“数字”;
否则,如果(_item ==“姓名”)changeitem =“名称”;
否则(_item ==“年龄”)changeitem =“年龄”;
否则,如果(_item ==“学院”)changeitem =“拼贴”;
否则if(_item ==“班级”)changeitem =“ class”;
否则,如果(_item ==“手机号码”)changeitem =“电话号码”;
SqlConnection conn =新的SqlConnection(“数据源= .;初始目录= StudentSystem;用户ID = sa;密码= 123456”);
字符串strsql =“从Student中选择” changeitem“,其中number ='” _number“'”;
SqlCommand com =新的SqlCommand(strsql,conn);
conn.Open();
SqlDataReader reader = com.ExecuteReader();
如果(!
System.Windows.Forms.MessageBox.Show(“学号不存在!”,“错误!”);
}
else
{
textBox9.Text = reader [changeitem] .ToString();
}
reader.Close();
conn.Close();
}
private void button9_Click(object sender,EventArgs e)
{
panel3.Visible = true;
panel1.Visible = false;
panel2.Visible = false;
panel4.Visible = false;
panel5.Visible = false;
comboBox3.Items.Clear();
SqlConnection conn =新的SqlConnection(“数据源= .;初始目录= StudentSystem;用户ID = sa;密码= 123456”);
字符串strsql =“选择学生的姓名,姓名”;
SqlCommand com =新的SqlCommand(strsql,conn);
conn.Open();
SqlDataReader reader = com.ExecuteReader();
while(reader.Read())
{
comboBox3.Items.Add(reader [“ number”]。ToString()“” reader [“ name”]。ToString());
}
reader.Close();
conn.Close();
}
private void button10_Click(object sender,EventArgs e)
{
字符串_text = comboBox3.Text.Trim();
string [] strarray = _text.Split('');
SqlConnection conn =新的SqlConnection(“数据源= .;初始目录= StudentSystem;用户ID = sa;密码= 123456”);
字符串strsql =“从学生那里删除number ='” strarray [0]“'”;
SqlCommand com =新的SqlCommand(strsql,conn);
conn.Open();
int i = com.ExecuteNonQuery();
如果(i> 0)System.Windows.Forms.MessageBox.Show(“删除成功!”,“成功!”);
else System.Windows.Forms.MessageBox.Show(“学号不存在!”,“错误!”);
conn.Close();
{
panel4.Visible = true;
panel1.Visible = false;
panel2.Visible = false;
panel3.Visible = false;
panel5.Visible = false;
comboBox4.Items.Clear();
comboBox5.Items.Clear();
SqlConnection conn =新的SqlConnection(“数据源= .;初始目录= StudentSystem;用户ID = sa;密码= 123456”);
字符串strsql =“选择学生的姓名,姓名”;
SqlCommand com =新的SqlCommand(strsql,conn);
conn.Open();
SqlDataReader reader = com.ExecuteReader();
while(reader.Read())
{
comboBox4.Items.Add(reader [“ number”]。ToString()“” reader [“ name”]。ToString());
}
reader.Close();
strsql =“从课程中选择课程号,课程名称”;
com =新的SqlCommand(strsql,conn);
reader = com.ExecuteReader();
while(reader.Read())
{
comboBox5.Items.Add(reader [“ coursenumber”]。ToString()“” reader [“ coursename”]。ToString());
}
reader.Close();
conn.Close();
}
private void button16_Click(对象发送者,
textBox12.Text =“”;
}
private void button17_Click(object sender,EventArgs e)
{
string _coursenumber = textBox12.Text.Trim();
字符串_coursename = textBox11.Text.Trim();
SqlConnection conn =新的SqlConnection(“数据源= .;初始目录= StudentSystem;用户ID = sa;密码= 123456”);
字符串strsql =“插入课程值('” _coursenumber“','” _coursename“')”;
SqlCommand com2 =新的SqlCommand(strsql,conn);
conn.Open();
int i = com2.ExecuteNonQuery();
如果(i> 0)System.Windows.Forms.MessageBox.Show(“
conn.Close();
}
private void button14_Click(object sender,EventArgs e)
{
panel5.Visible = true;
panel1.Visible = false;
panel2.Visible = false;
panel3.Visible = false;
panel4.Visible = false;
}
private void button12_Click(object sender,EventArgs e)
{
string _text = comboBox4.Text.Trim();
字符串_text1 = comboBox5.Text.Trim();
string [] strarray = _text.Split('');
string [] strarray_course = _text1.Split('');
SqlConnection conn =新的SqlConnection(“数据源= .;初始目录= StudentSystem;用户ID = sa;密码= 123456”);
字符串strsql =“从成绩中选择分数,其中学生号='” strarray [0]“'”“和课程号='” strarray_course [0]“'”;
SqlCommand com =新的SqlCommand(strsql,conn);
conn.Open();
SqlDataReader reader = com.ExecuteReader();
如果(!reader.Read())
{
System.Windows.Forms.MessageBox.Show(“成绩不存在!”,“错误!”);
}
else
{
textBox10.Text = reader [“ score”]。ToString();
}
reader.Close();
conn.Close();
}
private void button13_Click(object sender,EventArgs e)
{
int flag = 0;
字符串_text = comboBox4.Text.Trim();
字符串_text1 = comboBox5.Text.Trim();
字符串分数= textBox10.Text.Trim();
string [] strarray = _text.Split('');
string [] strarray_course = _text1.Split('');
SqlConnection conn =新的SqlConnection(“数据源= .;初始目录= StudentSystem;用户ID = sa;密码= 123456”);
字符串strsql =“从成绩中选择分数,其中学生号='” strarray [0]“'”“和课程号='” strarray_course [0]“'”;
SqlCommand com =新的SqlCommand(strsql,conn);
conn.Open();
SqlDataReader reader = com.ExecuteReader();
如果(!reader.Read())
{
标志= 1;
}
else
{
flag = 2;
}
reader.Close();
if(flag == 1)
{
string newstrsql =“插入分数值('” strarray [0]“','
SqlCommand com2 =新的SqlCommand(newstrsql,conn);
int i = com2.ExecuteNonQuery();
如果(i> 0)System.Windows.Forms.MessageBox.Show(“添加成功!”,“成功!”);
}
else if(flag == 2)
{
字符串newstrsql =“ update Score set score ='” score“'其中学生人数='” strarray [0]“'和coursenumber ='” strarray_course [0]“'”;
SqlCommand com2 =新的SqlCommand(newstrsql,conn);
int i = com2.ExecuteNonQuery();
如果(i> 0)System.Windows.Forms.MessageBox.Show(“修改成功!”,“成功!”);
}
conn.Close();
}
private void button16_Click_1(object sender,EventArgs e)
{
textBox11.Text =“”;
textBox12.Text =“”;
}
评论